﻿Option Explicit On
Option Strict On

Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Imports FRAMEWORK
Imports System.Drawing.Drawing2D
Public Class frm_Company
    Inherits asWins.Forms.BaseForm

    'Global Variable
    Dim DA As New FRAMEWORK.SQLDataAccess

#Region " Function and Procedure "
    'Private Sub Handler()
    '    ControlGotFocus(Me, Me)
    '    ControlLostFocus(Me, Me)
    'End Sub
    'Private Sub ControlGotFocus(ByVal parentCtr As Control, Optional ByVal ignoreControl As Control = Nothing)
    '    Dim ctr As Control
    '    For Each ctr In parentCtr.Controls
    '        If Not (ctr Is ignoreControl) Then
    '            If TypeOf ctr Is TextBox Then
    '                AddHandler ctr.GotFocus, AddressOf EvenHand.KeyEventHand.TextBox_GotFocus
    '            ElseIf TypeOf ctr Is ComboBox Then
    '                AddHandler DirectCast(ctr, ComboBox).GotFocus, AddressOf EvenHand.KeyEventHand.ComboBox_GotFocus
    '            End If
    '        End If
    '        ControlGotFocus(ctr, ignoreControl)
    '    Next
    'End Sub
    'Private Sub ControlLostFocus(ByVal parentCtr As Control, Optional ByVal ignoreControl As Control = Nothing)
    '    Dim ctr As Control
    '    For Each ctr In parentCtr.Controls
    '        If Not (ctr Is ignoreControl) Then
    '            If TypeOf ctr Is TextBox Then
    '                AddHandler ctr.LostFocus, AddressOf EvenHand.KeyEventHand.TextBox_LostFocus
    '            ElseIf TypeOf ctr Is ComboBox Then
    '                AddHandler DirectCast(ctr, ComboBox).LostFocus, AddressOf EvenHand.KeyEventHand.ComboBox_LostFocus
    '            End If
    '        End If
    '        ControlLostFocus(ctr, ignoreControl)
    '    Next
    'End Sub

    'Private Sub Get_ALL_Employee()
    '    Dim dt As DataTable

    '    Dim para(13) As SqlParameter

    '    para(0) = New SqlParameter("@ACTION", 3)
    '    para(1) = New SqlParameter("@Employee_Code", "")
    '    para(2) = New SqlParameter("@Department_ID", 0)
    '    para(3) = New SqlParameter("@Employee_Title", "")
    '    para(4) = New SqlParameter("@Employee_Fname", "")
    '    para(5) = New SqlParameter("@Employee_Lname", "")
    '    para(6) = New SqlParameter("@Employee_Position", "")
    '    para(7) = New SqlParameter("@Employee_Sale", 0)
    '    para(8) = New SqlParameter("@Employee_StatusAccount", 0)
    '    para(9) = New SqlParameter("@Employee_level", 0)
    '    para(10) = New SqlParameter("@Employee_Status", 0)
    '    para(11) = New SqlParameter("@Create_User", "")
    '    para(12) = New SqlParameter("@Update_User", "")
    '    dt = DA.ExecuteDataset(CommandType.StoredProcedure, "sp_SYS_EMPLOYEE", para).Tables(0)

    '    If dt.Rows.Count > 0 Then
    '        dgvDetails.DataSource = dt
    '        FormatHeader()
    '    Else
    '        dgvDetails.DataSource = Nothing
    '    End If


    'End Sub
    'Private Sub FormatHeader()
    '    With dgvDetails
    '        If .RowCount > 0 Then
    '            .Columns(0).HeaderText = "รหัส"
    '            .Columns(1).HeaderText = "คำนำหน้า"
    '            .Columns(2).HeaderText = "ชื่อ"
    '            .Columns(3).HeaderText = "นามสกุล"
    '            .Columns(4).HeaderText = "หน้าที่/ตำแหน่ง"
    '            .Columns(5).HeaderText = "แผนก"
    '            .Columns(6).HeaderText = "Sales"
    '            .Columns(7).HeaderText = "User Account"
    '            .Columns(8).HeaderText = "Level"

    '            .Columns(0).Width = 100
    '            .Columns(1).Width = 80 '.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    '            .Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    '            .Columns(3).Width = 100
    '            .Columns(4).Width = 100
    '            .Columns(5).Width = 100
    '            .Columns(6).Width = 100
    '            .Columns(7).Width = 100
    '            .Columns(8).Width = 100
    '        End If
    '    End With
    'End Sub
    'Private Sub ClearData(ByVal parentCtr As Control, Optional ByVal ignoreControl As Control = Nothing)
    '    Dim ctr As Control
    '    For Each ctr In parentCtr.Controls
    '        If Not (ctr Is ignoreControl) Then
    '            If TypeOf ctr Is TextBox Then
    '                ctr.Text = ""
    '            ElseIf TypeOf ctr Is ComboBox Then
    '                DirectCast(ctr, ComboBox).SelectedIndex = -1
    '            ElseIf TypeOf ctr Is ListBox Then
    '                CType(ctr, ListBox).Items.Clear()
    '            End If
    '        End If
    '        ClearData(ctr, ignoreControl)
    '    Next
    '    chkSales.Checked = False
    'End Sub

    'Private Sub Execute_Data()
    '    If cboDepart.SelectedIndex = -1 Then
    '        MessageBox.Show("กรุณาป้อนชื่อแผนก !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '        cboDepart.Focus()
    '        Exit Sub
    '    End If
    '    If txtTitle.Text.Trim() = "" Then
    '        MessageBox.Show("กรุณาป้อนคำนำหน้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '        txtTitle.Focus()
    '        Exit Sub
    '    End If
    '    If txtFirstName.Text.Trim() = "" Then
    '        MessageBox.Show("กรุณาป้อนชื่อก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '        txtFirstName.Focus()
    '        Exit Sub
    '    End If
    '    If txtLastName.Text.Trim() = "" Then
    '        MessageBox.Show("กรุณาป้อนนามสกุลก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '        txtLastName.Focus()
    '        Exit Sub
    '    End If

    '    Dim L_complete As Integer = 0
    '    If MessageBox.Show("คุณต้องการเพิ่มข้อมูล ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
    '        Try
    '            DA.BeginTransaction()
    '            Dim para(13) As SqlParameter

    '            para(0) = New SqlParameter("@ACTION", 1)
    '            para(1) = New SqlParameter("@Employee_Code", "")
    '            para(2) = New SqlParameter("@Department_ID", cboDepart.SelectedValue)
    '            para(3) = New SqlParameter("@Employee_Title", txtTitle.Text)
    '            para(4) = New SqlParameter("@Employee_Fname", txtFirstName.Text)
    '            para(5) = New SqlParameter("@Employee_Lname", txtLastName.Text)
    '            para(6) = New SqlParameter("@Employee_Position", txtPosition.Text)
    '            If chkSales.Checked Then
    '                para(7) = New SqlParameter("@Employee_Sale", 1)
    '            Else
    '                para(7) = New SqlParameter("@Employee_Sale", 0)
    '            End If
    '            para(8) = New SqlParameter("@Employee_StatusAccount", 0)
    '            para(9) = New SqlParameter("@Employee_level", 0)
    '            para(10) = New SqlParameter("@Employee_Status", 0)
    '            para(11) = New SqlParameter("@Create_User", FRAMEWORK.Framework.F_Username_Str)
    '            para(12) = New SqlParameter("@Update_User", "")
    '            L_complete = DA.ExecuteNonQuery(DA.Transaction, CommandType.StoredProcedure, "sp_SYS_EMPLOYEE", para)
    '            If L_complete > 0 Then
    '                DA.CommitTransaction()
    '                MessageBox.Show("เพิ่มข้อมูลเรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '                Call ClearData(Me, Me)
    '                Call Get_ALL_Employee()
    '            Else
    '                DA.RollBackTransaction()
    '                MessageBox.Show("เกิดข้อผิดพลาด", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '                Exit Sub
    '            End If

    '        Catch ex As Exception
    '            DA.RollBackTransaction()
    '            MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก " & ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '            Exit Sub
    '        End Try

    '        cboDepart.Focus()

    '    Else
    '        Exit Sub
    '    End If
    'End Sub
    'Private Sub Update_Data(ByVal index As Integer, ByVal tmp As String)
    '    If txtCode.Text.Trim() = "" Then
    '        MessageBox.Show("กรุณาเลือกข้อมูลก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '        txtCode.Focus()
    '        Exit Sub
    '    End If
    '    If txtFirstName.Text.Trim() = "" Then
    '        MessageBox.Show("กรุณาป้อนชื่อก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '        txtFirstName.Focus()
    '        Exit Sub
    '    End If

    '    Dim L_complete As Integer = 0
    '    If MessageBox.Show("คุณต้องการ" & tmp & "ข้อมูล ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
    '        Try
    '            DA.BeginTransaction()
    '            Dim para(13) As SqlParameter

    '            para(0) = New SqlParameter("@ACTION", 2)
    '            para(1) = New SqlParameter("@Employee_Code", txtCode.Text)
    '            para(2) = New SqlParameter("@Department_ID", cboDepart.SelectedValue)
    '            para(3) = New SqlParameter("@Employee_Title", txtTitle.Text)
    '            para(4) = New SqlParameter("@Employee_Fname", txtFirstName.Text)
    '            para(5) = New SqlParameter("@Employee_Lname", txtLastName.Text)
    '            para(6) = New SqlParameter("@Employee_Position", txtPosition.Text)
    '            If chkSales.Checked Then
    '                para(7) = New SqlParameter("@Employee_Sale", 1)
    '            Else
    '                para(7) = New SqlParameter("@Employee_Sale", 0)
    '            End If
    '            para(8) = New SqlParameter("@Employee_StatusAccount", 0)
    '            para(9) = New SqlParameter("@Employee_level", 0)
    '            para(10) = New SqlParameter("@Employee_Status", index)
    '            para(11) = New SqlParameter("@Create_User", FRAMEWORK.Framework.F_Username_Str)
    '            para(12) = New SqlParameter("@Update_User", "")
    '            L_complete = DA.ExecuteNonQuery(DA.Transaction, CommandType.StoredProcedure, "sp_SYS_EMPLOYEE", para)
    '            If L_complete > 0 Then
    '                DA.CommitTransaction()
    '                MessageBox.Show(tmp & "ข้อมูลเรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '                Call ClearData(Me, Me)
    '                Call Get_ALL_Employee()
    '            Else
    '                DA.RollBackTransaction()
    '                MessageBox.Show("เกิดข้อผิดพลาด", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '                Exit Sub
    '            End If

    '        Catch ex As Exception
    '            DA.RollBackTransaction()
    '            MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก " & ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '            Exit Sub
    '        End Try

    '        cboDepart.Focus()

    '    Else
    '        Exit Sub
    '    End If
    'End Sub
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim lgb As New LinearGradientBrush(ClientRectangle, Color.LightSkyBlue, Color.Aquamarine, LinearGradientMode.Vertical)
        e.Graphics.FillRectangle(lgb, ClientRectangle)

        lgb.Dispose()
    End Sub

    'Private Sub GetDepartment()
    '    Dim dt As DataTable
    '    Dim para(8) As SqlParameter

    '    para(0) = New SqlParameter("@ACTION", 3)
    '    para(1) = New SqlParameter("@Department_ID", 0)
    '    para(2) = New SqlParameter("@Department_Name", "")
    '    para(3) = New SqlParameter("@Department_ShortName", "")
    '    para(4) = New SqlParameter("@Department_Status", 0)
    '    para(5) = New SqlParameter("@Department_Remark", "")
    '    para(6) = New SqlParameter("@Create_User", "")
    '    para(7) = New SqlParameter("@Update_User", "")
    '    dt = DA.ExecuteDataset(CommandType.StoredProcedure, "sp_SYS_DEPARTMENT", para).Tables(0)

    '    If dt.Rows.Count > 0 Then
    '        cboDepart.DataSource = dt
    '        cboDepart.DisplayMember = "Department_Name"
    '        cboDepart.ValueMember = "Department_ID"

    '    Else
    '        cboDepart.DataSource = Nothing
    '    End If
    'End Sub
#End Region

    Private Sub frm_Company_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        groupBox1.BackColor = Color.FromArgb(0, 0, 0, 0)
        panel1.BackColor = Color.FromArgb(0, 0, 0, 0)

        Dim FD As New FormFader
        FD.FadeIn(Me, 0.25)
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click

    End Sub
End Class